package com.bizhibihui.ordermeal.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bizhibihui.ordermeal.entity.BizFoodTags;
import com.bizhibihui.ordermeal.mapper.BizFoodTagsMapper;
import com.bizhibihui.ordermeal.service.BizFoodTagsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 */
@Service
@AllArgsConstructor
public class BizFoodTagsServiceImpl extends ServiceImpl<BizFoodTagsMapper, BizFoodTags> implements BizFoodTagsService {

    private final BizFoodTagsMapper bizFoodTagsMapper;

    @Override
    public int removeByFoodId(Integer foodId) {
        return bizFoodTagsMapper.delete(Wrappers.<BizFoodTags>lambdaQuery().eq(BizFoodTags::getFoodId, foodId));
    }

    @Override
    public void insertList(Integer[] tagIds, Integer foodId) {
        Date date = new Date();
        for (Integer tagId : tagIds) {
            BizFoodTags articleTags = new BizFoodTags();
            articleTags.setTagId(tagId);
            articleTags.setFoodId(foodId);
            articleTags.setCreateTime(date);
            articleTags.setUpdateTime(date);
            bizFoodTagsMapper.insert(articleTags);
        }
    }
}
